From 0c08e0d74fc7a92f0fe5f671797ebfe99f69424d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 10 Nov 2014 09:36:36 -0800 Subject: [PATCH] Don't panic on unused overrides This previously did a failing hashtable lookup when an `Option`-returning `get` would suffice. --- src/cargo/ops/cargo_rustc/custom_build.rs | 12 +++++++----- tests/test_cargo_compile_custom_build.rs | 24 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/custom_build.rs b/src/cargo/ops/cargo_rustc/custom_build.rs index 342f67e11..d4d945b51 100644 --- a/src/cargo/ops/cargo_rustc/custom_build.rs +++ b/src/cargo/ops/cargo_rustc/custom_build.rs @@ -212,11 +212,13 @@ impl BuildState { } } let mut outputs = HashMap::new(); - for (name, output) in config.host.overrides.into_iter() { - outputs.insert((sources[name].clone(), KindHost), output); - } - for (name, output) in config.target.overrides.into_iter() { - outputs.insert((sources[name].clone(), KindTarget), output); + let i1 = config.host.overrides.into_iter().map(|p| (p, KindHost)); + let i2 = config.target.overrides.into_iter().map(|p| (p, KindTarget)); + for ((name, output), kind) in i1.chain(i2) { + match sources.get(&name) { + Some(id) => { outputs.insert((id.clone(), kind), output); } + None => {} + } } BuildState { outputs: Mutex::new(outputs) } } diff --git a/tests/test_cargo_compile_custom_build.rs b/tests/test_cargo_compile_custom_build.rs index cd143bc9c..deec359fa 100644 --- a/tests/test_cargo_compile_custom_build.rs +++ b/tests/test_cargo_compile_custom_build.rs @@ -297,6 +297,30 @@ test!(overrides_and_links { ", compiling = COMPILING, running = RUNNING).as_slice())); }) +test!(unused_overrides { + let (_, target) = ::cargo::ops::rustc_version().unwrap(); + + let p = project("foo") + .file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.5.0" + authors = [] + build = "build.rs" + "#) + .file("src/lib.rs", "") + .file("build.rs", "fn main() {}") + .file(".cargo/config", format!(r#" + [target.{}.foo] + rustc-flags = "-L foo -L bar" + foo = "bar" + bar = "baz" + "#, target).as_slice()); + + assert_that(p.cargo_process("build").arg("-v"), + execs().with_status(0)); +}) + test!(links_passes_env_vars { let p = project("foo") .file("Cargo.toml", r#" -- 2.30.2